<?php
	
autoLoader();

// display( $_REQUEST );
// display( $_POST ); exit;

if( false == isset( $_POST['Submit'] ) || false == valStr( $_POST['charge_type_id'] ) ) { 
	$str = '';
	$str .= '<form name=myform method=post action=modules.php?file=charge_types&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
	$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
	echo $str;
	exit;
}

if( true == isset( $_POST['operation'] ) && 'insert' == strtolower( $_POST['operation'] ) ) {
	
	$objBaseChargeTypes = new BaseChargeTypes();
	$objBaseChargeTypes->setChargeCatagoryId( $_POST['charge_catagory_id'] );
	$objBaseChargeTypes->setName( $_POST['name'] );
	$objBaseChargeTypes->setDescription( $_POST['description'] );
	$objBaseChargeTypes->setCbArea( $_POST['cacharge'] );
	$objBaseChargeTypes->setOutOfCa( $_POST['outcacharge'] );
	$objBaseChargeTypes->setBelowPriorityLine( $_POST['bplcharge'] );

	
	$objBaseChargeTypes->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseChargeTypes->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseChargeTypes->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseChargeTypes->insert() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_charge_types&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
} else if( true == isset( $_POST['operation'] ) && 'update' == strtolower( $_POST['operation'] ) ) {

	$objChargeTypes 	= new ChargeTypes();
	$objBaseChargeTypes 	= $objChargeTypes->fetchChargeTypesById( $_POST['charge_type_id'] );
	
	$objBaseChargeTypes->setChargeCatagoryId( $_POST['charge_catagory_id'] );
	$objBaseChargeTypes->setName( $_POST['name'] );
	$objBaseChargeTypes->setDescription( $_POST['description'] );
	$objBaseChargeTypes->setCbArea( $_POST['cacharge'] );
	$objBaseChargeTypes->setOutOfCa( $_POST['outcacharge'] );
	$objBaseChargeTypes->setBelowPriorityLine( $_POST['bplcharge'] );

	$objBaseChargeTypes->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseChargeTypes->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseChargeTypes->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseChargeTypes->update() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_charge_types&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
}

?>